package com.yihu.cms.action;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yihu.cms.service.ActivityService;
import com.yihu.web.bean.Activity;
import com.yihu.web.bean.vo.ActivityQuery;
/***
 * 活动
 * @author Aaron
 *
 */
@Controller
public class ActivityController extends BaseController{
	private final Logger logger = LoggerFactory.getLogger(ActivityController.class); 
	private ActivityService service = new ActivityService();
	
	@RequestMapping(value = "/activity", method = RequestMethod.POST)
	public @ResponseBody Object add(@RequestBody Activity a) {
		return service.addActivity(a);
	}
	@RequestMapping(value = "/activity/{id}", method = RequestMethod.DELETE)
	public @ResponseBody Object deleteActivity(@PathVariable("id") String id) {
		return service.deleteActivity(id);
	}
	@RequestMapping(value = "/activity/{id}", method = RequestMethod.PUT)
	public @ResponseBody Object updateActivity(@PathVariable("id") String id, @RequestBody Activity a) {
		if(StringUtils.isNotBlank(id)){
			a.setId(id);
		}
		return service.updateActivity(a);
	}
	@RequestMapping(value = "/activity/{id}", method = RequestMethod.GET)
	public @ResponseBody Object getActivity(@PathVariable("id") String id) {
		return service.getActivity(id);
	}
	
	//活动列表
	@RequestMapping(value = "/activity/list" , method = RequestMethod.GET)
	public @ResponseBody Object getActivities(ActivityQuery query) {
		return service.getActivities(query);
	}
	//已报名的活动列表
	@RequestMapping(value = "/activity/signup/list" , method = RequestMethod.GET)
	public @ResponseBody Object getSignUpActivities(ActivityQuery query) {
		return service.getSignUpActivities(query);
	}

	

}
